home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 1.iso / util / printps.zip / PRINTPS.C < prev    next >
C/C++ Source or Header  |  1994-01-19  |  4KB  |  153 lines

  1. #define lineentete 815
  2. #define firstline  795
  3. #define __MSC /* For Borland C++ */
  4. #include <bios.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. void PrintProlog() ;
  9. void PrintEnd() ;
  10. void SelectCourier (int corps) ;
  11. void SelectTimes   (int corps) ;
  12. void SelectHelv    (int corps) ;
  13. void PrintTextAt(int x,int y,unsigned char * text) ;
  14. void PrintPage();
  15.  
  16.  
  17. FILE * fsort ;
  18. /*=========================================================================*/
  19. /*                               lit_chaine                                */
  20. /*=========================================================================*/
  21.  
  22. /* lit_chaine lit la chaine de caractères buf dans le fichier         */
  23. /* *stream. la chaine est terminée lorsque l'on rencontre un séparateur   */
  24. /* fin de ligne ou fin de fichier                                         */
  25.  
  26. char lit_chaine (FILE * stream,char * buf,int lgMax)
  27. {
  28.    char c;
  29.    int pos=0;
  30.  
  31.    do
  32.    {
  33.       c=getc(stream) ;
  34.       if (c != 10) if ((pos++)<lgMax) *(buf++) = c ;
  35.  
  36.    } while ((c!='\0') && (c!='\n') && (c!=EOF));
  37.  
  38.    *buf = '\0';
  39.    return c ;
  40. }
  41.  
  42. int env_car_printer (char c)
  43. {
  44.   int status;
  45.         /* status :
  46.             bit   meaning if TRUE
  47.                         0     Printer timed out
  48.             1     Not used
  49.                         2     Not used
  50.                         3     I/O error
  51.                         4     Printer selected
  52.                         5     Out of paper
  53.             6     Acknowledge
  54.                         7     Printer not busy  */
  55.      if (c!='\n')
  56.         status=_bios_printer(_PRINTER_WRITE,0,c) & 255;
  57.       else
  58.        {
  59.          status = _bios_printer(_PRINTER_WRITE,0,13) & 255;
  60.          status = _bios_printer(_PRINTER_WRITE,0,10) & 255;
  61.        }
  62.      if (status != 0) printf("STATUS %d",status) ;
  63.      return status ;
  64. }
  65.  
  66.  
  67. void SendText(char *pText)
  68. {
  69.   fputs (pText,fsort) ;
  70. /*  while ((*pText) != '\0')
  71.     (void) env_car_printer(*(pText++)) ; */
  72. }
  73.  
  74. void EcrEntete(char * text,int nopage)
  75. {
  76.   SelectTimes (11) ;
  77.   PrintTextAt (20,lineentete,text) ;
  78.   if (nopage != -1)
  79.     {
  80.       char txtpage[10] ;
  81.       sprintf (txtpage,"page n° %d",nopage) ;
  82.       PrintTextAt(500,lineentete,txtpage) ;
  83.     }
  84.   SelectCourier (10) ;
  85. }
  86.  
  87. void PrintDoc(char * szFileName)
  88. {
  89. char ligne[512] ;
  90. int nopage = 1 ;
  91. FILE * FicAscii ;
  92. unsigned int nl = firstline ;
  93.   if ((FicAscii = fopen(szFileName,"rt")) == NULL)
  94.     {
  95.       puts ("Fichier impossible à ouvrir") ;
  96.       return ;
  97.     }
  98.  
  99.   PrintProlog () ;
  100.   SelectCourier (10) ;
  101.   while (lit_chaine(FicAscii,ligne,100) != EOF)
  102.      {
  103.        PrintTextAt (20,nl-=11,ligne) ;
  104.        if (nl < 30)
  105.      {
  106.        EcrEntete (szFileName,nopage ++) ;
  107.        PrintPage() ;
  108.        nl = firstline ;
  109.      }
  110.      }
  111.   if (nopage == 1) EcrEntete(szFileName,-1) ;
  112.           else EcrEntete(szFileName,nopage) ;
  113.   PrintPage () ;
  114.   PrintEnd ();
  115. }
  116.  
  117. void ConvMaj (char * dest,char * src,int nmax)
  118. {
  119.   int i = 0 ;
  120.   while (*src != '\0' && i < nmax)
  121.     {
  122.       if (*src >= 'a' && *src <= 'z')
  123.          *(dest++) = (*(src++)) - 32 ;
  124.     else *(dest++) = (*(src++)) ;
  125.       i ++ ;
  126.     }
  127.  *dest = '\0' ;
  128.  
  129. }
  130.  
  131. main(int argc,char *argv[])
  132. {
  133. char fileName [80] ;
  134.   puts ("PrintPS 1.01 (C) 1991 Gilles Vollant\n");
  135.     if (argc < 2)
  136.     {
  137.       puts("Syntaxe : PrintPS filename.ext [filesort.eps]\n") ;
  138.       puts(" filename.ext étant le fichier à imprimer,\n" \
  139.          "et filesort.eps un éventuel fichier de sortie " \
  140.          "(PRN est utilise) par défaut.\n") ;
  141.       return 1 ;
  142.     }
  143.  
  144.   if (argc == 2)  fsort = fopen("prn.eps","w") ;
  145.          else fsort = fopen(argv[2],"w") ;
  146.  
  147.   ConvMaj (fileName,argv[1],50) ;
  148.   PrintDoc(fileName) ;
  149.   fclose(fsort) ;
  150.  
  151.   return 0 ;
  152. }
  153.